﻿package plugin.npcDialog.ui.panels.boss
{
    import com.core.*;
    import flash.events.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instance.*;
    import plugin.instances.*;
    import uiresource.npcdialogs.*;
    import view.*;
    import view.light.*;
    import view.mornExtends.*;
    import view.uilt.*;

    public class CaiLiaoFb extends ClfbUI implements INpcDialogContent
    {
        private const instanceids:Array;
        private var _curmapid:int = 0;

        public function CaiLiaoFb()
        {
            this.instanceids = [15010, 15005, 15006, 15008, 15009];
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            label_fanhui.clickHandler = new Handler(this.fanhuiHandler);
            list1.renderHandler = new Handler(this.itemHandler);
            list.renderHandler = new Handler(this.itemRender);
            btn_jr.clickHandler = new Handler(this.jinruHandler);
            buy.addEventListener(MouseEvent.CLICK, this.buyclickHandler);
            return;
        }// end function

        protected function buyclickHandler(event:MouseEvent) : void
        {
            DialogMgr.instance.open(AppDialog.SC_BUY, {storeId:422});
            return;
        }// end function

        private function jinruHandler() : void
        {
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            var _loc_1:* = ConfigDictionary.data.instance[this._curmapid];
            var _loc_2:* = ModelProxy.getValue("data", "user");
            if (_loc_1.open_level > _loc_2.level)
            {
                WarningManager.show(32, [_loc_1.open_level]);
                return;
            }
            if (_loc_1.rein > _loc_2.rein)
            {
                WarningManager.show(33, [_loc_1.rein]);
                return;
            }
            if (_loc_1.needitem == "")
            {
            }
            else
            {
                _loc_3 = (_loc_1.needitem as String).split("#");
                _loc_4 = ItemUilt.getAllCount(_loc_3[0]);
                if (_loc_3[1] > _loc_4)
                {
                    WarningManager.show(120, [_loc_3[1]]);
                    return;
                }
            }
            PluginManager.instance.sendToServer("instance", CMDInstance.NpcInstance, {mapid:this._curmapid, type:0});
            ModelProxy.change("plugin", "close", "npcdialog");
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param2 < list.length)
            {
                (param1 as FlashItem).data = list.array[param2];
            }
            return;
        }// end function

        private function fanhuiHandler() : void
        {
            box1.visible = true;
            box2.visible = false;
            return;
        }// end function

        public function close() : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            return;
        }// end function

        private function itemHandler(param1:Component, param2:int) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:String = null;
            var _loc_6:Array = null;
            var _loc_7:Object = null;
            if (param2 < list1.length)
            {
                (param1.getChildByName("label_fbxz") as Label).text = list1.array[param2].tltle;
                if (list1.array[param2].rein == 0)
                {
                    (param1.getChildByName("label_fblv") as Label).text = list1.array[param2].open_level + "级";
                }
                else
                {
                    (param1.getChildByName("label_fblv") as Label).text = list1.array[param2].rein + "转";
                }
                _loc_3 = list1.array[param2].mapid;
                (param1.getChildByName("label_fbname") as LinkButton).label = ConfigDictionary.data.maplist[_loc_3].name;
                _loc_4 = 0;
                _loc_5 = list1.array[param2].limit_times;
                _loc_6 = _loc_5.split(" ");
                _loc_7 = ModelProxy.getValue("data", "dayinstances");
                if (_loc_7 == null || !_loc_7.hasOwnProperty(_loc_3))
                {
                    _loc_4 = _loc_6[1];
                }
                else
                {
                    _loc_4 = _loc_6[1] - int(_loc_7[_loc_3]);
                }
                (param1.getChildByName("label_cs") as Label).text = _loc_4 + "/" + _loc_6[1];
                if (_loc_4 == 0)
                {
                    (param1.getChildByName("label_cs") as Label).color = 13051156;
                }
                else
                {
                    (param1.getChildByName("label_cs") as Label).color = 5485622;
                }
                (param1.getChildByName("label_fbname") as LinkButton).clickHandler = new Handler(this.fbclickHandler, [_loc_3]);
            }
            return;
        }// end function

        public function updatebag() : void
        {
            var _loc_2:Array = null;
            var _loc_3:int = 0;
            if (this._curmapid == 0)
            {
                return;
            }
            var _loc_1:* = ConfigDictionary.data.instance[this._curmapid];
            if (_loc_1 == null)
            {
                return;
            }
            if (_loc_1.needitem == "")
            {
                needbox.visible = false;
            }
            else
            {
                needbox.visible = true;
                _loc_2 = (_loc_1.needitem as String).split("#");
                labeli_geshu.text = _loc_2[1];
                _loc_3 = ItemUilt.getAllCount(_loc_2[0]);
                labeli_yongyougeshu.text = _loc_3.toString();
                if (_loc_3 < _loc_2[1])
                {
                    labeli_yongyougeshu.color = 13051156;
                    buy.visible = true;
                    LightFactory.showlight(buy);
                }
                else
                {
                    labeli_yongyougeshu.color = 5485622;
                    buy.visible = false;
                }
            }
            return;
        }// end function

        public function fbclickHandler(param1:int) : void
        {
            var _loc_8:Array = null;
            var _loc_9:int = 0;
            this._curmapid = param1;
            var _loc_2:int = 0;
            var _loc_3:* = ConfigDictionary.data.instance[param1];
            if (fbnameLabel == null)
            {
                return;
            }
            if (this._curmapid == 0)
            {
                return;
            }
            fbnameLabel.text = ConfigDictionary.data.maplist[param1].name;
            var _loc_4:* = _loc_3.total_time / 60;
            label_time.text = _loc_4 + "分钟";
            if (_loc_3.rein == 0)
            {
                label_lv.text = _loc_3.open_level + "级";
            }
            else
            {
                label_lv.text = "[" + _loc_3.rein + "转]" + _loc_3.open_level + "级";
            }
            var _loc_5:* = _loc_3.limit_times;
            var _loc_6:* = _loc_3.limit_times.split(" ");
            var _loc_7:* = ModelProxy.getValue("data", "dayinstances");
            if (ModelProxy.getValue("data", "dayinstances"))
            {
                _loc_2 = int(_loc_7[param1]);
            }
            label_sycs.text = _loc_6[1] - _loc_2 + "/" + _loc_6[1];
            if (_loc_2 == _loc_6[1])
            {
                WarningManager.show(45);
                return;
            }
            buy.visible = false;
            LightFactory.clearlight(buy);
            if (_loc_3.needitem == "")
            {
                needbox.visible = false;
            }
            else
            {
                needbox.visible = true;
                _loc_8 = (_loc_3.needitem as String).split("#");
                labeli_geshu.text = _loc_8[1];
                _loc_9 = ItemUilt.getAllCount(_loc_8[0]);
                labeli_yongyougeshu.text = _loc_9.toString();
                if (_loc_9 < _loc_8[1])
                {
                    labeli_yongyougeshu.color = 13051156;
                    buy.visible = true;
                    LightFactory.showlight(buy);
                }
                else
                {
                    labeli_yongyougeshu.color = 5485622;
                }
            }
            box1.visible = false;
            box2.visible = true;
            this.showItem(_loc_3.show);
            return;
        }// end function

        private function showItem(param1:String) : void
        {
            var _loc_2:* = new ItemSplit();
            var _loc_3:* = _loc_2.doSplits(param1, "&", "/", "#");
            list.array = _loc_3[0];
            return;
        }// end function

        public function show(param1:Object, param2:Object) : void
        {
            box1.visible = true;
            box2.visible = false;
            var _loc_3:* = ConfigDictionary.data.instance;
            var _loc_4:Array = [];
            var _loc_5:int = 0;
            while (_loc_5 < this.instanceids.length)
            {
                
                _loc_4.push(_loc_3[this.instanceids[_loc_5]]);
                _loc_5++;
            }
            list1.array = _loc_4;
            return;
        }// end function

        public function update(param1:Object, param2:int = 0) : void
        {
            return;
        }// end function

    }
}
